package com.tvein.sanguo.action.view
{
	//flash
	import flash.net.LocalConnection;
	//pureMVC
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.utilities.fabrication.components.FlashApplication;
	import org.puremvc.as3.multicore.utilities.fabrication.patterns.mediator.FlashMediator;	
	//custom
	import com.tvein.sanguo.action.common.GameConstants;
	import com.tvein.sanguo.Action;
	import com.tvein.sanguo.action.controller.system.ActionInit;
	import com.tvein.sanguo.action.controller.system.ActionClose;
	import com.tvein.sanguo.action.controller.system.ActionSystem;
	import com.tvein.sanguo.action.controller.system.ActionScript;
	import com.tvein.sanguo.action.controller.login.ActionLogin;
	import com.tvein.sanguo.action.controller.role.ActionRole;
	import com.tvein.sanguo.action.controller.menu.ActionMenu;
	import com.tvein.sanguo.action.controller.tool.ActionTool;
	import com.tvein.sanguo.action.controller.skill.ActionSkill;
	import com.tvein.sanguo.action.controller.command.ActionCommand;
	import com.tvein.sanguo.action.controller.room.ActionRoom;
//
	public class SystemMediator extends FlashMediator
	{
		public static const NAME:String = 'SystemMediator';
		
		public function SystemMediator(viewComponent:Object)
		{
			super(NAME, viewComponent);
		}
		
		public function get action():Action
		{
			return viewComponent as Action;
		}
		
		//Custom
		override public function onRegister() : void
        {
			facade.registerCommand(GameConstants.ACTION_INIT, ActionInit);
			facade.registerCommand(GameConstants.ACTION_CLOSE, ActionClose);
			facade.registerCommand(GameConstants.ACTION_SYSTEM, ActionSystem);
			facade.registerCommand(GameConstants.ACTION_SCRIPT, ActionScript);
			facade.registerCommand(GameConstants.ACTION_LOGIN, ActionLogin);
			facade.registerCommand(GameConstants.ACTION_ROLE, ActionRole);
			facade.registerCommand(GameConstants.ACTION_MENU, ActionMenu);
			facade.registerCommand(GameConstants.ACTION_TOOL, ActionTool);
			facade.registerCommand(GameConstants.ACTION_SKILL, ActionSkill);
			facade.registerCommand(GameConstants.ACTION_COMMAND, ActionCommand);
			facade.registerCommand(GameConstants.ACTION_ROOM, ActionRoom);
        }
		
		override public function listNotificationInterests() : Array
		{
			var interests:Array = super.listNotificationInterests();
			interests.push(GameConstants.MODULE_INVOKE);
			interests.push(GameConstants.GAME_CONSOLE);
			return interests;
		}
		
		override public function handleNotification(notification:INotification) : void
		{
			switch(notification.getName())
			{
				case GameConstants.MODULE_INVOKE:
					trace(GameConstants.MODULE_ACTION + " Invoke : " + notification.getBody()[0]);
					switch(notification.getBody()[0])
					{
						case "-init":
							sendNotification(GameConstants.ACTION_INIT, notification.getBody()[1]);
							break;
						case "-close":
							sendNotification(GameConstants.ACTION_CLOSE, notification.getBody()[1]);
							break;
						case "-system":
							sendNotification(GameConstants.ACTION_SYSTEM, notification.getBody()[1]);
							break;
						case "-login":
							sendNotification(GameConstants.ACTION_LOGIN, notification.getBody()[1]);
							break;
						case "-role":
							sendNotification(GameConstants.ACTION_ROLE, notification.getBody()[1]);
							break;
						case "-menu":
							sendNotification(GameConstants.ACTION_MENU, notification.getBody()[1]);
							break;
						case "-tool":
							sendNotification(GameConstants.ACTION_TOOL, notification.getBody()[1]);
							break;
						case "-skill":
							sendNotification(GameConstants.ACTION_SKILL, notification.getBody()[1]);
							break;
						case "-command":
							sendNotification(GameConstants.ACTION_COMMAND, notification.getBody()[1]);
							break;
						case "-room":
							sendNotification(GameConstants.ACTION_ROOM, notification.getBody()[1]);
							break;
						case "-script":
							sendNotification(GameConstants.ACTION_SCRIPT, notification.getBody()[1]);
							break;
					}
					break;
			}
			
			try
			{
				new LocalConnection().connect("Tvein");
				new LocalConnection().connect("Tvein");
			}
			catch (error : Error)
			{
			
			}
		}
    }
}